/**
 * 
 */
package com.cipe.cmrs.bean;

import com.cipe.cmrs.util.StringUtils;

/**
 * @author Incepio
 * 
 */
public class CodeDescriptionBean {
    private Integer id;
    private String code;
    private String description;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getEscapedDescription() {
        return StringUtils.INSTANCE.escape(description);
    }

    public String getDisplayName() {
        StringBuilder builder = new StringBuilder();
        builder.append(getValue(code));
        builder.append(getValue(getEscapedDescription()));
        String result = builder.toString();
        if (result.endsWith(" - ")) {
            return result.substring(0, result.lastIndexOf('-'));
        } else {
            return result;
        }
    }

    private String getValue(String val) {
        if (org.apache.commons.lang.StringUtils.isNotBlank(val)) {
            return val + " - ";
        } else {
            return "";
        }
    }
}
